import request from '@/utils/request';
import type { ArticleParam } from '@/types/admin/article';

export async function fetchArticle(params: ArticleParam) {
  try {
    const res = await request.post("/admin/article/page", { params });
    console.log('文章列表请求接口', res);
    return res.data;
  } catch (error) {
    console.error('文章列表请求出错:', error);
    throw error;
  }
}

export async function fetchSingleArticle(id: string | number) {
  try {
    const res = await request.get(`/admin/article/${id}`);
    return res.data;
  } catch (error) {
    console.error('单篇文章请求出错:', error);
    throw error;
  }
}

export async function deleteArticles(params: number[]) {
  try {
    const res = await request.delete(`/admin/article/batch`, { params });
    console.log('文章删除成功:', res.data);
    return res.data;
  } catch (error) {
    console.error('文章删除请求出错:', error);
    throw error;
  }
}
